import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
const fieldAlignOptions = [
  {
    label: '居中',
    value: 'center',
  },
  {
    label: '居左',
    value: 'left',
  },
  {
    label: '居右',
    value: 'right',
  },
];
const fieldShowOptions = [
  {
    label: '显示',
    value: '1',
  },
  {
    label: '隐藏',
    value: '0',
  },
];
export const columns: BasicColumn[] = [
  {
    title: '字段名称',
    dataIndex: 'field',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  {
    title: '字段标题',
    dataIndex: 'title',
    width: 100,
    ellipsis: true,
    resizable: true,
    slots: {
      customRender: 'title',
    },
  },
  {
    title: '标题别名',
    dataIndex: 'fieldTitle',
    width: 100,
    ellipsis: true,
    resizable: true,
    helpMessage: '为空则默认使用字段名称',
  },
  {
    title: '位置',
    dataIndex: 'fieldAlign',
    width: 100,
    ellipsis: true,
    resizable: true,
    customRender: ({ value }) => {
      return fieldAlignOptions.find((item) => item.value == value)?.label;
    },
  },
  {
    title: '显示',
    dataIndex: 'show',
    width: 100,
    ellipsis: true,
    resizable: true,
    customRender: ({ value }) => {
      return value == '1' ? '显示' : '隐藏';
    },
  },
  {
    title: '顺序号',
    dataIndex: 'order',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  {
    title: '宽度',
    dataIndex: 'width',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  {
    title: '表头分组',
    dataIndex: 'fieldGroup',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  {
    title: '行分组',
    dataIndex: 'fieldRowGroup',
    width: 100,
    ellipsis: true,
    resizable: true,
    customRender: ({ record }) => {
      let val = record['fieldRowGroup'];
      return h('span', val == '1' ? '是' : '否');
    },
  },
  {
    title: '链接',
    dataIndex: 'link',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'title',
    label: '字段标题',
    component: 'Input',
    colProps: { span: 24 },
    slot: 'title',
  },
  {
    field: 'fieldTitle',
    label: '标题别名',
    component: 'Input',
    colProps: { span: 24 },
    helpMessage: '为空则默认使用字段名称',
  },
  {
    field: 'fieldAlign',
    label: '位置',
    component: 'Select',
    colProps: { span: 24 },
    defaultValue: 'center',
    componentProps: {
      options: fieldAlignOptions,
    },
  },
  {
    field: 'fieldShow',
    label: '显示',
    component: 'Select',
    colProps: { span: 24 },
    defaultValue: '1',
    componentProps: {
      options: fieldShowOptions,
    },
  },
  {
    field: 'fieldOrder',
    label: '顺序号',
    component: 'InputNumber',
    colProps: { span: 24 },
  },
  {
    field: 'fieldWidth',
    label: '宽度',
    component: 'InputNumber',
    defaultValue: 150,
    colProps: { span: 24 },
  },
  {
    field: 'fieldGroup',
    label: '表头分组',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'fieldRowGroup',
    label: '行分组',
    colProps: {
      span: 24,
    },
    component: 'RadioGroup',
    defaultValue: '0',
    componentProps: {
      options: [
        {
          label: '是',
          value: '1',
        },
        {
          label: '否',
          value: '0',
        },
      ],
    },
  },
  {
    field: 'fieldLink',
    label: '链接',
    component: 'Input',
    colProps: { span: 24 },
  },
];

//映射字段
export const mappingFieldsFormSchema: FormSchema[] = [
  {
    field: 'fieldName',
    label: '本表字段', //id="fieldNameMapForList" name="fieldName"
    required: true,
    component: 'Select',
    colProps: { span: 24 },
  },
  {
    field: 'otherFormCode',
    label: '表单',
    required: true,
    component: 'Select',
    colProps: { span: 24 },
  },
  {
    field: 'otherField',
    label: '表单字段',
    required: true,
    component: 'Select',
    colProps: { span: 24 },
    // otherShowField
    slot: 'otherField',
  },
  {
    field: 'fieldShow',
    label: '显示',
    component: 'Select',
    colProps: { span: 24 },
    defaultValue: '1',
    componentProps: {
      options: [
        {
          label: '显示',
          value: '1',
        },
        {
          label: '隐藏',
          value: '0',
        },
      ],
    },
  },
  {
    field: 'fieldOrder',
    label: '顺序号',
    component: 'InputNumber',
    colProps: { span: 24 },
  },
  {
    field: 'fieldWidth',
    label: '宽度',
    component: 'InputNumber',
    defaultValue: 150,
    colProps: { span: 24 },
  },
];
//多重映射字段
export const mappingFieldsFormSchema2: FormSchema[] = [
  {
    field: 'fieldName',
    label: '字段',
    required: true,
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'fieldOrder',
    label: '顺序号',
    component: 'InputNumber',
    colProps: { span: 24 },
  },
  {
    field: 'fieldWidth',
    label: '宽度',
    component: 'InputNumber',
    defaultValue: 150,
    colProps: { span: 24 },
  },
  {
    field: 'message',
    label: ' ',
    component: 'Input',
    defaultValue: 150,
    colProps: { span: 24 },
    render: () => '规则：本表字段:对应表单编码:对应字段:获取字段:......',
  },
];
export const defaultFlowList = [
  {
    value: 'flowId',
    label: '-流程号-',
  },
  {
    value: 'cws_status',
    label: '-记录状态-',
  },
  {
    value: 'cws_cur_handler',
    label: '-当前处理-',
  },
  {
    value: 'flow_begin_date',
    label: '-流程开始时间-',
  },
  {
    value: 'flow_end_date',
    label: '-流程结束时间-',
  },
];

export const defaultCodeList = [
  {
    value: 'ID',
    label: '-ID-',
  },
  {
    value: 'cws_creator',
    label: '-创建者-',
  },
  {
    value: 'cws_action',
    label: '-流程环节-',
  },
  // {
  //   value: 'cws_progress',
  //   label: '-进度-',
  // },
  {
    value: 'cws_flag',
    label: '-冲抵状态-',
  },
  {
    value: 'colOperate',
    label: '-操作列-',
  },
  {
    value: 'cws_create_date',
    label: '-创建时间-',
  },
  {
    value: 'cws_modify_date',
    label: '-修改时间-',
  },
  {
    value: 'cws_visited',
    label: '-是否已读-',
  },
  {
    value: 'cws_id',
    label: '-关联ID-',
  },
];

export const defaultMappingFieldList = [
  {
    value: 'id',
    label: 'ID',
  },
  {
    value: 'cws_id',
    label: 'cws_id',
  },
];

// <option value="ID">-ID-</option>
// 					<option value="cws_creator">-创建者-</option>
// 					<option value="cws_progress">-进度-</option>
// 					<%if (fd.isFlow()) {%>
// 					<option value="flowId">-流程号-</option>
// 					<option value="cws_status">-记录状态-</option>
// 					<option value="cws_cur_handler">-当前处理-</option>
// 					<option value="flow_begin_date">-流程开始时间-</option>
// 					<option value="flow_end_date">-流程结束时间-</option>
// 					<%}%>
// 					<option value="cws_flag">-冲抵状态-</option>
// 					<option value="colOperate">-操作列-</option>
// 					<option value="cws_create_date">-创建时间-</option>
// 					<option value="cws_modify_date">-修改时间-</option>
// 					<option value="cws_visited">-是否已读-</option>
// 					<option value="cws_id">-关联ID-</option>
// 					<%
// 						Vector v = fd.getFields();
// 						ir = v.iterator();
// 						while (ir.hasNext()) {
// 							FormField ff = (FormField) ir.next();
// 					%>
// 					<option value="<%=ff.getName()%>"><%=ff.getTitle()%>
// 					</option>
// 					<%
// 						}

// 						ModuleRelateDb mrd = new ModuleRelateDb();
// 						Vector v2 = mrd.getFormsRelatedWith(formCode);
// 						Iterator ir2 = v2.iterator();
// 						while (ir2.hasNext()) {
// 							FormDb frmDb = (FormDb) ir2.next();
// 							ir = frmDb.getFields().iterator();
// 							while (ir.hasNext()) {
// 								FormField ff = (FormField) ir.next();
// 					%>
// 					<option style="BACKGROUND: #eeeeee" value="main:<%=frmDb.getCode()%>:<%=ff.getName()%>"><%=frmDb.getName()%>：<%=ff.getTitle()%>
// 					</option>
